import { math, v2, Vec2 } from "cc"
import { StateDefine } from "../StateDefine"
import { ActorState } from "./ActorState"

export class Run extends ActorState {
    velocity: Vec2 = v2()
    onEnter() {

        // this.animation.play(StateDefine.Run)
        this.animation.crossFade(StateDefine.Run)
    }
    onExit() {

    }
    update(deltaTime: number): void {

        // this.velocity.set(this.actor.input.x, this.actor.input.y)
        // this.velocity.multiplyScalar(this.actor.linearSpeed)
        // this.actor.rigidBody.linearVelocity = this.velocity
        // if (this.actor.input.length() <= math.EPSILON) {
        //     this.actor.stateMgr.transit(StateDefine.Idle)
        // }
        this.velocity.set(this.actor.input.x, this.actor.input.y)
        this.velocity.multiplyScalar(this.actor.linearSpeed)
        this.actor.rigidBody.linearVelocity = this.velocity

        if (this.actor.input.length() <= math.EPSILON) {
            this.actor.stateMgr.transit(StateDefine.Idle)
        }
    }
    canTransit(to: StateDefine): boolean {
        if (to == this.id) {
            return false
        }
        return true
    }
}
